<?php
// 检查菜品处理状态的脚本

try {
    $config = ['hostname'=>'127.0.0.1', 'database'=>'yingyang', 'username'=>'root', 'password'=>'root', 'charset'=>'utf8mb4'];
    $dsn = 'mysql:host=' . $config['hostname'] . ';dbname=' . $config['database'] . ';charset=' . $config['charset'];
    $pdo = new PDO($dsn, $config['username'], $config['password']);
    
    // 查询最近处理的菜品
    $stmt = $pdo->query('SELECT id, name, cook_time, steps, ai_called FROM fa_food_dish WHERE ai_called = 1 ORDER BY updatetime DESC LIMIT 5');
    $dishes = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    echo '最近处理的菜品:' . PHP_EOL;
    foreach ($dishes as $dish) {
        echo 'ID: ' . $dish['id'] . ', 名称: ' . $dish['name'] . PHP_EOL;
        echo '  烹饪时间: ' . $dish['cook_time'] . PHP_EOL;
        echo '  制作步骤长度: ' . strlen($dish['steps']) . ' 字符' . PHP_EOL;
        echo '  AI已调用: ' . $dish['ai_called'] . PHP_EOL . PHP_EOL;
    }
    
    // 统计信息
    $stmt = $pdo->query('SELECT COUNT(*) as total FROM fa_food_dish');
    $total = $stmt->fetch(PDO::FETCH_ASSOC);
    
    $stmt = $pdo->query('SELECT COUNT(*) as processed FROM fa_food_dish WHERE ai_called = 1');
    $processed = $stmt->fetch(PDO::FETCH_ASSOC);
    
    $stmt = $pdo->query('SELECT COUNT(*) as unprocessed FROM fa_food_dish WHERE ai_called = 0');
    $unprocessed = $stmt->fetch(PDO::FETCH_ASSOC);
    
    echo '总菜品数: ' . $total['total'] . PHP_EOL;
    echo '已处理数: ' . $processed['processed'] . PHP_EOL;
    echo '未处理数: ' . $unprocessed['unprocessed'] . PHP_EOL;
    
} catch (Exception $e) {
    echo '查询失败: ' . $e->getMessage() . PHP_EOL;
}
?>